<?php
echo $this->Form->create('Post', array(
	'url' => array(
		'controller' => 'posts',
		'action' => 'add',
	),
	'type' => 'file'
));

echo $this->Form->input('title', array(
	// 'placeholder' => '',
	'label' => __('Nadpis'),
	'error' => __('Povinné pole.'),
	'class' => 'form-control'
));

echo $this->Form->input('image', array(
	// 'placeholder' => '',
	'required' => '',
	'type' => 'file',
	'label' => __('Obrázok (nepovinné)'),
	'error' => __('Povolené formáty su jpg, png, gif. Maximálna veľkosť obrázku je ') . MAX_IMAGE_UP_SIZE_MB . 'MB.',
	'class' => 'form-control'
));

echo $this->Form->input('description', array(
	// 'placeholder' => '',
	'label' => __('Text'),
	'error' => __('Povinné pole.'),
	'class' => 'form-control'
));

// ak nie je setnuty defaultne je v db nasteveny na 0 teda na story
if(isset($category_id)){
	echo $this->Form->input('category_id', array(
		'type'	=> 'hidden',
		'value' => $category_id
	));
}else{
    echo $this->Form->input('category_id', array(
    	'type'=>'select', 
    	'options'=> array(
			POST_CATEGORY_STORY => 'príbeh',
			POST_CATEGORY_DRAWING => 'nástenné umenie'
		),
		'label'=>__('Kategória'),
		'class'=>'form-control'
    ));
}

echo $this->Form->submit(__(' '), array(
	'id' => 'add-submit',
));

echo $this->Form->end();

echo isset($formMessage) ? $this->Html->div('form-message', $formMessage) : '';
?>
<script type="text/javascript">
$(function() {
	$('#add-post-wrapper form').on('submit', function() {
		$('#add-post-wrapper').addClass('loading');

		var formData = new FormData($(this)[0]);

		$.ajax({
			url: '/posts/add/' + Date.now(),
			type: 'POST',
			data: formData,
			beforeSend: function() {
				$('#add-post-wrapper').addClass('loading');
			},
			success: function (data) {
				$('#add-post-wrapper').html(data);
				$('#add-post-wrapper').removeClass('loading');
			},
			cache: false,
			contentType: false,
			processData: false
		});

		return false;
	});
});
</script>